<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <title>{block name="title"}{$title|default=''}{if !empty($title)} · {/if}{:sysconf('site_name')}{/block}</title>
    <meta name="renderer" content="webkit">
    <meta name="format-detection" content="telephone=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1">
    <link href="__ROOT__/static/plugs/layui/css/layui.css?v={:date('ymd')}" rel="stylesheet">
    <style>.layui-card {
        margin: 0
    }

    .layui-card .layui-card-body a {
        display: block;
        font-size: 12px;
        color: #666
    }</style>
    <script src="__ROOT__/static/plugs/angular/angular.min.js"></script>
</head>
<body id="MessageContainer">
<div class="layui-card" ng-repeat="x in list">
    <div class="layui-card-header layui-bg-gray">
        <a target="_top" href="{:url('@admin')}?messagecode={{x.code}}#{{x.url}}" ng-bind="x.title"></a>
        <a href="javascript:void(0)" ng-click="setReadState(x.code)" style="position:absolute;right:0;top:0;width:50px;text-align:center">忽略</a>
    </div>
    <div class="layui-card-body">
        <a target="_top" href="{:url('@admin')}?messagecode={{x.code}}#{{x.url}}" ng-bind="x.desc"></a>
        <a target="_top" href="{:url('@admin')}?messagecode={{x.code}}#{{x.url}}" ng-bind="x.create_at"></a>
    </div>
</div>
<script>
    (function () {
        var index = parent.layer.getFrameIndex(window.name);
        var app = angular.module("MessageContainer", []).run(callback);
        angular.bootstrap(document.getElementById(app.name), [app.name]);

        function callback($rootScope, $http, $timeout, $interval) {
            $rootScope.list = [];
            $rootScope.setReadState = function (code) {
                $http.post('{:url("@admin/api.message/set")}', {code: code}).then(function () {
                    refresh(false);
                });
            };
            refresh.call(this, true), $interval(function () {
                parent.layer.iframeAuto(index);
                // top.$body.trigger('resize');
            }, 10);

            function refresh(isCallback) {
                $http.get('{:url("@admin/api.message/gets")}').then(function (ret) {
                    $rootScope.list = (ret.data || {data: []}).data;
                    if ($rootScope.list < 1) parent.layer.style(index, {height: '0'});
                    if (isCallback !== false) $timeout(refresh, 2000);
                });
            }
        }
    })();
</script>
</body>
</html>

